<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */

class Modules_Core_Widgets_Localeswitcher_Widget extends Gio_Core_Widget
{
	protected function showAction()
	{
		$request = $this->getRequest();
		$type = $this->getParam('locale_type', 'full');
		
		$configs = Gio_Core_Config_Xml::getConfig();
		if (!isset($configs->localization->enable) || 'false' == $configs->localization->enable) {
			return;
		}

		/**
		 * Get base URL (http://localhost/gio_cms)
		 */
		$baseUrl = rtrim($request->getBaseUrl(), '/');
		$links   = array();

		$arrayDetails = (array)$configs->localization->languages->details;
		foreach ($arrayDetails as $locale => $details) {
			$array = explode('|', (string)$details);
			$links[$locale] = array(
				'href'		  => $baseUrl . '/' . $locale,
				'localName'   => $array[1],
				'englishName' => $array[2],
			);
		}
		
		$this->view->type = $type;
		$this->view->links = $links;
	}
	
	public function configAction()
	{
		$localeType = $this->getParam('locale_type', 'full');
		$this->view->localeType = $localeType;
		
		$this->view->moduleName = Gio_Core_Widget::getIntance()->getModuleName();
		$this->view->widgetName = Gio_Core_Widget::getIntance()->getWidgetName();
		$this->view->widgetIndex = $this->getParam('widget_index');
	}
}
